{template 'header'}
<link href="./resource/css/app.css" rel="stylesheet">
<ul class="nav nav-tabs">
    <li class=""><a href="{php echo $this->createWeburl('video')}">短视频管理</a></li>
    <li class=""><a href="{php echo $this->createWeburl('video', array('op' => 'addShow'));}">添加短视频</a></li>
    <li class=""><a href="{php echo $this->createWeburl('videoCategory');}">短视频分类</a></li>
    <li class=""><a href="{php echo $this->createWeburl('videoCategory', array('op' => 'addShow'));}">添加短视频</a></li>
    <li class=""><a href="{php echo $this->createWeburl('videoAuthor');}">短视频作者</a></li>
    <li class=""><a href="{php echo $this->createWeburl('videoAuthor', array('op' => 'addShow'));}">添加作者</a></li>
    <li class="active"><a href="{php echo $this->createWeburl('videoCollect');}">采集视频</a></li>
</ul>
<form action="./index.php" method="get" class="form-horizontal">
    <input type="hidden" name="c" value="site">
    <input type="hidden" name="a" value="entry">
    <input type="hidden" name="m" value="bh_farm">
    <input type="hidden" name="do" value="videoCollect">
    <div class="form-group">
        <label class="col-xs-12 col-sm-1 control-label">视频分类</label>
        <div class="col-sm-1 col-xs-12">
            <select class="select valid" id="category_id" name="category_id" size="1" aria-invalid="false" style="width: 150px;">
                <option  value="0">请选择</option>
                {loop $category $item}
                <option  value="{$item['id']}" {if $category_id == $item['id']  } selected {/if}  >{$item['name']}</option>
                {/loop}
            </select>
        </div>

        <label class="col-xs-12 col-sm-1 control-label">视频作者</label>
        <div class="col-sm-1 col-xs-12">
            <select class="select valid" id="author_id" name="author_id" size="1" aria-invalid="false" style="width: 150px;">
                <option  value="0">请选择</option>
                {loop $author $item}
                <option  value="{$item['id']}" {if $author_id ==$item['id']  } selected {/if}>{$item['name']}</option>
                {/loop}
            </select>
        </div>
        <label class="col-xs-12 col-sm-1 control-label">视频关键词</label>
        <div class="col-sm-2 col-xs-12">
            <input type="text" class="form-control" placeholder="请输入关键词进行搜索" name="keyWord"  value="{$keyWord}" />
        </div>
        <div class="col-sm-2 col-xs-12">
            <select  class="select valid" name="cur" size="1" aria-invalid="false" style="width: 150px;">
                {if $cur !=0}
                <option value="{$page_prev}" {if $page_prev == $cur } selected {/if}>上一页</option>
                {/if}
                <option value="{$cur}" {if $cur == $cur } selected {/if}>{$strPage}</option>
                <option value="{$page_next}" {if $page_next == $cur } selected {/if}>下一页</option>
            </select>
        </div>
        <div class="col-xs-12 col-sm-1 col-md-2 col-lg-2">
            <button type="submit" class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
        </div>
    </div>
</form>
<span style="margin: 30px; color: red">批量操作注意事项:建议一次处理不超过20条数据</span>
<div class="panel panel-default">
    <div class="table-responsive panel-body">
        <table class="table table-hover">
            <thead class="navbar-inner">
            <tr>
                <th style="width:80px;"> 选择</th>
                <th style="width:80px;">视频标题</th>
                <th style="width:80px;">封面图片</th>
                <th style="width:80px;">Vid</th>
                <th style="width:80px;">状态</th>
                <th style="width:80px;">添加时间</th>
                <th style="width:80px;">操作</th>
            </tr>
            </thead>
            <tbody>
            {loop $list $item}
            <tr>
                <td><input type="checkbox" name="collect" value="{$item['id']}" />{$item['id']}</td>
                <td>{$item['title']}</td>
                <td><img src="{php echo $item['cover_image']}" width="39px" height="39px"></td>
                <td>{$item['vid']}</td>
                <td>{php echo  $item['status'] ==1 ? '显示': '隐藏'}</td>
                <td>{php echo date('Y-m-d H:i:s', $item['created'])}</td>
                <td>
                    {if $item['status'] ==1}
                    <a href="javascript:;" data-id="{$item['id']}" class="btn btn-success btn-sm storage">待入库</a>
                    {else}
                    <a href="javascript:;" class="btn btn-info btn-sm">已入库</a>
                    {/if}
                    <a href="javascript:;" data-id="{$item['id']}" class="delete btn btn-danger btn-sm">删除</a>
                </td>
            </tr>
            {/loop}
            </tbody>
        </table>
    </div>
    <div class="css" style="margin-bottom: 15px">
        <input  type="button" class="btn btn-default" id="allCheck" value="全选"/>
        <input type="button" class="btn btn-default" id="noCheck" value="全不选"/>
        <input type="button" class="btn btn-default" id="revCheck" value="反选"/>
        <input type="button" class="btn btn-success" id="audit" value="批量入库"/>
    </div>
    {$pager}
</div>
<script type="application/javascript">
    $(function () {
        $('.delete').click(function () {
            if (!confirm('确认要删除该采集的数据')) {
                return false;
            }
            id = $(this).data('id');
            $.post('', {id:id, op:'delete'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('删除失败');
                }

            }, 'json')
        });

        $('.sort').blur(function () {
            var sort = $(this).val();
            var  id = $(this).data('id');
            $.post('', {id:id,sort:sort, op:'sort'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('排序失败');
                }

            }, 'json')
        });



        $('.storage').click(function () {
            if (!confirm('确认要入库')) {
                return false;
            }
            id = $(this).data('id');
            var category_id = $("#category_id").val();
            var author_id = $("#author_id").val();
            $.post('', {id:id,category_id:category_id,author_id : author_id, op:'storage'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('请选择要入库的作者或分类');
                }

            }, 'json')
        });

        $('.settop').click(function () {

            id = $(this).data('id');
            $.post('', {id:id, op:'settop'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('删除失败');
                }

            }, 'json')
        });
    });


    $(function() {
        // 全选
        $("#allCheck").click(function(){
            $(":checkbox").prop("checked",true);
        });
        // 全不选
        $("#noCheck").click(function(){
            $(":checkbox").prop("checked",false);
        });
        // 反选
        $("#revCheck").click(function(){
            $(":checkbox").each(function(){
                var check = $(this).prop("checked");
                $(this).prop("checked",!check);
            });

        });

        //通过审核
        $("#audit").click(function () {
            var chk_value =[];
            $('input[name="collect"]:checked').each(function(){
                chk_value.push($(this).val());
            });
            var taskIds = chk_value.join(",");
            var category_id = $("#category_id").val();
            var author_id = $("#author_id").val();
            $.post('', {taskIds:taskIds, category_id:category_id, author_id:author_id, op:'audit'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('请选择要入库的作者或分类');
                }
            }, 'json')

        })

        //拒绝审核
        $("#refuse").click(function () {
            var chk_value =[];
            $('input[name="collect"]:checked').each(function(){
                chk_value.push($(this).val());
            });
            var taskIds = chk_value.join(",");

            $.post('', {taskIds:taskIds, op:'refuse'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('请选择要入库的作者或分类');
                }

            }, 'json')

        })
    });

</script>